<?php

namespace App\Livewire;

use App\Filament\Enums\AssetType;
use Filament\Forms\Components\MarkdownEditor;
use Filament\Forms\Components\TextInput;
use Filament\Support\Enums\Alignment;
use Filament\Support\Enums\IconPosition;
use Filament\Support\Enums\IconSize;
use Filament\Support\Enums\MaxWidth;
use JaOcero\RadioDeck\Forms\Components\RadioDeck;
use Livewire\Component;
use Filament\Actions\Action;
use Filament\Actions\Contracts\HasActions;
use Filament\Forms\Contracts\HasForms;
use Filament\Facades\Filament;
use Filament\Forms\Concerns\InteractsWithForms;
use Filament\Actions\Concerns\InteractsWithActions;
use Filament\Forms\Components\Textarea;
use App\Http\Controllers\RechargeController;
use App\Filament\Enums\PayType;
use Filament\Notifications\Notification;
use App\Classes\CommonAction;

class UserDashboardLeft extends Component implements HasActions, HasForms
{
    use InteractsWithActions;
    use InteractsWithForms;

    public function render()
    {
        $user = Filament::auth()->getUser();
        return view('livewire.user-dashboard-left', compact('user'));
    }

    public function editProfileAction():Action
    {
        return CommonAction::editProfileAction('standalone');
    }

    public function rechargeAction(): Action
    {
        return Action::make('recharge')
            ->label('充值余额')
            ->icon('heroicon-m-currency-dollar')
            ->form([
                TextInput::make('amount')->label('金额'),
                RadioDeck::make('payment_method')
                    ->label('支付方式')
                    ->options(PayType::class)
                    ->descriptions(PayType::class)
                    ->icons(PayType::class)
                    ->required()
                    ->iconSize(IconSize::Large)
                    ->iconPosition(IconPosition::Before)
                    ->alignment(Alignment::Center)
                    ->color('danger')
                    ->extraCardsAttributes([ // Extra Attributes to add to the card HTML element
                        'class' => 'payment-method-btn',
                    ])->columns(3),
            ])->action(function(array $arguments, array $data){
                $amount = $data['amount'];
                $payment_method = $data['payment_method'];
                new RechargeController($payment_method, $amount);
            })->modalAlignment(Alignment::Center)
            ->modalWidth(MaxWidth::TwoExtraLarge);
    }

    public function buyPlanAction(): Action
    {
        $user = Filament::auth()->getUser();

        $word = "升级会员";

        if (isset($user->plan_id)){
            $word = "续费会员";
        }

        return Action::make('buyPlan')
            ->label($word)
            ->icon('heroicon-m-shopping-cart')
            ->url('/user/plans');
    }
}
